package com.example.jn_dxs.ViewModel;

import com.alibaba.fastjson.JSONObject;
import com.example.jn_dxs.Base.BaseViewModel;
import com.example.jn_dxs.Base.Observer;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class LoginVM extends BaseViewModel {
    public void getLogin(String username,String password,boolean rememberMe){
        loadingStatus.postValue(1);
        apiService.getLogin(username,password,rememberMe).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<JSONObject>() {
            @Override
            public void onNext(JSONObject object) {
                super.onNext(object);
                loadingStatus.postValue(2);
                if (object.getIntValue("code")==0){
                    dataObject.postValue(object);
                }else {
                    msg.postValue(object.getString("msg"));
                }
            }

        });
    }
}
